/*
 
 */
package com.jme3.gde.gui.extra.xam.model.impl;

import javax.xml.namespace.QName;
import com.jme3.gde.gui.extra.xam.model.NiftyComponent;
import com.jme3.gde.gui.extra.xam.model.NiftyComponentFactory;
import com.jme3.gde.gui.extra.xam.model.NiftyModel;
import com.jme3.gde.gui.extra.xam.model.NiftyQName;
import com.jme3.gde.gui.extra.xam.model.NiftyType;
import com.jme3.gde.gui.extra.xam.model.visitor.ChildComponentUpdateVisitor;
import org.netbeans.modules.xml.xam.ComponentUpdater;
import org.netbeans.modules.xml.xam.ModelSource;
import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
import org.w3c.dom.Element;

/**
 * Implementation of Nifty domain model.
 *
 * @author cuongnguyen
 */
// Generated by XAM AutoGen Tool v0.2
public class NiftyModelImpl extends NiftyModel {
    
    private NiftyComponent rootComponent;
    private NiftyComponentFactory componentFactory;
    
    public NiftyModelImpl(ModelSource source) {
        super(source);
        componentFactory = new NiftyComponentFactoryImpl(this);
    }
    
    public NiftyComponent getRootComponent() {
        return rootComponent;
    }

    public NiftyComponentFactory getFactory() {
        return componentFactory;
    }

    public NiftyType getNiftyType() {
        return (NiftyType) getRootComponent();
    }

    public NiftyComponent createRootComponent(Element root) {
        QName q = root == null ? null : AbstractDocumentComponent.getQName(root);
        if (root != null ) {
            if (NiftyQName.NIFTYTYPE.getQName().equals(q)) {
                rootComponent = new NiftyTypeImpl(this, root);
            }
        } 
        
        return getRootComponent();
    }

    protected ComponentUpdater<NiftyComponent> getComponentUpdater() {
        return new ChildComponentUpdateVisitor<NiftyComponent>();
    }

    public NiftyComponent createComponent(NiftyComponent parent, Element element) {
        return getFactory().create(element, parent);
    }

}
